<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/page/common/commonConfig.jsp" %>

<html>

<head>
    <base href="<%=basePath%>">
    <title>资源信息标签页</title>
    <script src="<%=basePath%>component/tabbar.js"></script>
    <script src="<%=basePath%>component/grid.js"></script>
    <script type='text/javascript' src='<%=basePath%>dwrsystem/engine.js'></script>
	<script type='text/javascript' src='<%=basePath%>dwrsystem/interface/resourceService.js'></script>
    <script>
	var resourceId = '${param.resourceId}';
	
	function operateTabbar(tabbar){
		tabbar.addTab("a1", "资源信息", "130px");
		tabbar.addTab("a2", "资源图片", "130px");
		tabbar.addTab("a3", "下级资源列表", "130px");
		tabbar.setContentHref("a1", ("<%=basePath%>system-resource/ResourceAction!resourceQueryForEdit.action?resourceId="+resourceId) );
		tabbar.setContent("a2", "resourceImgOperate");
		tabbar.setContentHref("a3", ("<%=basePath%>system-resource/ResourceAction!resourceQuery.action?tresourcesystem.superResourceId="+resourceId) );
		tabbar.setTabActive("a1");
		tabbar.attachEvent("onSelect", function(id){
            if(id == 'a2'){
            	dhxGrid.loadHavedImage();
            }
            return true;
        });
	}
	
	var dhxGrid = null;
	function initDhxGrid(){
		dhxGrid = {
			mygrid : null,//createGridNormal('tableGridContainer'),
			havedImage:false,
			configDataTable : function () {
				this.mygrid = createGridNormal('resourceImgOperate'),
			    this.mygrid.setHeader("序号,资源图片,图片名称");
			    this.mygrid.setInitWidths("50,130,*");
			    this.mygrid.setColAlign("right,center,left");
			    this.mygrid.setColSorting("int");
			    this.mygrid.setColTypes("ro,img,ro");
			    this.mygrid.attachEvent('onRowSelect', this.selectPic);
			    this.mygrid.init();
			    setSkin(this.mygrid);
			    this.mygrid.loadXML('<%=basePath%>system-resource/ResourceAction!resourceImgs.action');
			},
			selectPic : function (id,ind){
				try {
					if(dhxGrid.havedImage){
						resourceService.updateTResourceImg({"resourceId":resourceId,"imgName":id},function(data){
							parent.parent.notifyCreater('修改成功');
						});
					}else{
						resourceService.insertTResourceImg({"resourceId":resourceId,"imgName":id},function(data){
							parent.parent.notifyCreater('添加成功');
						});
						dhxGrid.havedImage = true;
					}
				} catch (ex) {
					alert(ex);
				}
			},
			loadHavedImage :function(){
				try {
					resourceService.selectTResourceImg({"resourceId":resourceId},
						function(data){
							if(data!=''){
								dhxGrid.havedImage = true;
								dhxGrid.mygrid.selectRowById(data[0].imgName);
							}
						});
				} catch (ex) {
					alert(ex);
				}
			}
		};
		dhxGrid.configDataTable();
	}
	
	
	$(function (){
		initDhxGrid();
		createTabbar('tab','top',operateTabbar);
	});
	</script>
</head>

<body>
	<div id="tab" style="width:100%; height:100%"></div>
	<div id='resourceImgOperate' style="width:100%;height:100%;display: none;" ></div>
</body>

</html>
